<% if @tag_type %>
  <h3>Available <%= @tag_type.classify %> Options (<%= @tags.count %>)</h3>

  <% if @tag_type == "fandom" && @tags.count > ArchiveConfig.MAX_OPTIONS_TO_SHOW %>

    <!-- sort tags out by media -->
    <% Media.by_name.each do |medium| %>
      <% if @tags.with_parents([medium]).count > 0 %>
        <h3><%= medium.name %> (<%= @tags.with_parents([medium]).count %>)</h3>
        <ul>
          <%= @tags.with_parents([medium]).by_name_without_articles.map {|tag| content_tag(:li, tag.name)}.join("\n").html_safe %>
        </ul>
      <% end %>
    <% end %>
    <% if @tags.with_no_parents.count > 0 %>
      <h3>No Media Specified (<%= @tags.with_no_parents.count %>)</h3>
      <ul>
        <%= @tags.with_no_parents.by_name_without_articles.map {|tag| content_tag(:li, tag.name)}.join("\n").html_safe %>
      </ul>
    <% end %>
    
  <% elsif (@tag_type == "character" || @tag_type == "relationship") && @tags.count > ArchiveConfig.MAX_OPTIONS_TO_SHOW %>

    <!-- sort tags out by fandom -->    
    <% @tag_set.with_type("fandom").by_name_without_articles.each do |fandom| %>
      <% if @tags.with_parents([fandom]).count > 0 %>
        <h3><%= fandom.name %> (<%= @tags.with_parents([fandom]).count %>)</h3>
        <ul>
          <%= @tags.with_parents([fandom]).by_name_without_articles.map {|tag| content_tag(:li, tag.name)}.join("\n").html_safe %>
        </ul>
      <% end %>
    <% end %>
    <% if @tags.with_no_parents.count > 0 %>
      <h3>No Fandom Specified (<%= @tags.with_no_parents.count %>)</h3>
      <ul>
        <%= @tags.with_no_parents.by_name_without_articles.map {|tag| content_tag(:li, tag.name)}.join("\n").html_safe %>
      </ul>
    <% end %>

  <% else %>

    <!-- show all the tags alphabetically -->
    <ul>
      <%= @tags.by_name_without_articles.map {|tag| content_tag(:li, tag.name)}.join("\n").html_safe %>
    </ul>

  <% end %>

<% else %>

  <!-- recursively render by type -->
  <% TagSet::TAG_TYPES.each do |type| %>
    <% @tag_type = type %>
    <% @tags = @tags.with_type(type) %>
    <% if @tags.count > 0 %>
      <%= render "tag_set_tags" %>
    <% end %>
  <% end %>

<% end %>
        